﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.DAL
{
    public class Thesis
    {
        private Model.ThesisDB db = new Model.ThesisDB();
        /// <summary>
        /// 将论文信息写入数据表中
        /// </summary>
        /// <param name="thesis"></param>
        public void Insert(Model.Thesis thesis)
        {
            db.Thesis.InsertOnSubmit(thesis);
            db.SubmitChanges();
        }

        /// <summary>
        /// 获取论文名称对应的ID号
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public Guid Search(string title)
        {
            Guid guid = (from t in db.Thesis
                         where t.Title == title
                         select t.ID).FirstOrDefault();
            return guid;
        }
        /// <summary>
        /// 获取数据库中的所有论文名称
        /// </summary>
        /// <returns></returns>
        public string[] Search()
        {
            string[] thesis = (from t in db.Thesis
                               select t.Title).ToArray();
            return thesis;
        }
        /// <summary>
        /// 根据论文ID号删除论文对应信息
        /// </summary>
        /// <param name="guid"></param>
        public void Del(Guid guid)
        {
            Model.Thesis th = db.Thesis.Single(e => e.ID == guid);
            db.Thesis.DeleteOnSubmit(th);
            db.SubmitChanges();
        }
    }
}
